package cn.flyingroc.travelbook.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

/**
 * 创建数据库对象
 * @author xuzhenqin
 *
 */
public class DatabaseHelper extends SQLiteOpenHelper {

	//数据库名称
	private final static String DATABASE_NAME = "TravelBook";
	
	//数据库版本号
	private final static int DATABASE_VERSION = 1;
	
	public static final String DATABASE_TABLE = "MYPOI";

	//数据表创建SQL语句
	private static final String DATABASE_CREATE = "CREATE TABLE IF NOT EXISTS "+ DATABASE_TABLE +
	"(ID INTEGER PRIMARY KEY autoincrement not null," +
	"TITLE TEXT not null,"+
	"DESC TEXT null,"+
	"LAT DOUBLE null,LON DOUBLE null," +
	"PHOTONAME TEXT null," +
	"CREATETIME TEXT not null)";
	
	public DatabaseHelper(Context context) {
		
		//调用父类构造方法创建数据库
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		
		//执行创建数据库SQL语句
		db.execSQL(DATABASE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

		//判断数据库是否存在
		db.execSQL("DROP TABLE IF EXISTS "+DATABASE_TABLE);
		onCreate(db);
	}

}
